package com.agile.leetcode.valid;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

/**
 * @author chenzhangkun
 * @ClassName ValidParenthessPractice
 * @description: TODO
 * @date 2025年01月14日
 */
public class ValidParenthesesPractice {

	public static void main(String[] args) {


		String str = "[{[({[()]})]}]";

		System.out.println(isValid(str));


	}

	public static boolean isValid(String s) {
		Map<String, String> map = new HashMap<>();
		map.put("]", "[");
		map.put("}", "{");
		map.put(")", "(");
		Stack<String> stack = new Stack<>();
		for (int i = 0; i < s.length() ; i++) {
			char c = s.charAt(i);
			if (map.containsKey(String.valueOf(c))) {
				if (!map.get(String.valueOf(c)).equals(stack.pop())) {
					return false;
				}
			} else {
				stack.push(String.valueOf(c));
			}
		}
		return stack.isEmpty();
	}


}
